package com.jixi.controller;

import com.jixi.common.result.PageResult;
import com.jixi.common.result.Result;
import com.jixi.pojo.vo.OrderStatusVo;
import com.jixi.service.OrderDailyService;
import com.jixi.service.StudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Tag(name = "查询该班级学生详情")
@RestController
@RequestMapping("/teacher/class")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @Autowired
    private OrderDailyService orderDailyService;
    /**
     * 查询管理班级详情
     *
     * @return 用餐人总数，学生id，学生名字，学生身份证号码，套餐id，状态
     * */
    @GetMapping("/student/detail")
    @Operation(summary = "查询管理班级学生详情")
    public Result getClassDetail(Integer pageNum, Integer pageSize,Long classId,String date,String studentName,String studentCard){
        //执行查询
        PageResult studentPageQuery= studentService.getClassDetail(pageNum,pageSize,classId,date,studentName,studentCard);
        return Result.success(studentPageQuery);
    }
    /**
     *班级各订餐状态统计
     *
     * @return 已完成定餐人数，已退餐人数，未完成定餐人数
     * */
    @GetMapping("/order/status")
    @Operation(summary = "查询管理班级学生详情")
    public Result<OrderStatusVo> getOrderStatus(Long classId,String date){
        //构造查询
        //1.已完成定餐人数
        Long haveOrder = orderDailyService.getHaveOrder(classId,date);
        //2.已退餐人数
        Long returnOrder = orderDailyService.getReturnOrder(classId,date);
        //3.未完成定餐人数
        Long totalNum = orderDailyService.getNoOrder(classId);
        Long noOrder = totalNum - haveOrder-returnOrder;
        //封装返回
        OrderStatusVo orderStatusVo = new OrderStatusVo(haveOrder, returnOrder, noOrder);
        return Result.success(orderStatusVo);
    }
}
